#include "TransformController.h"
#include "Utils.h"

using namespace std;
using namespace gull::core;


TransformController::TransformController(ISceneNode* node):
NodeController(node)
{
}

TransformController::~TransformController()
{
}

void
TransformController::rotateAboutAxis(const Vector3D& v, double degree)
{
	Vector3D n = v;
	n.normalize();
	double rad = degToRad(degree);
	
	Vector3D trans = m_transform[3];
	setPosition(-trans);
	Matrix4x3 mat = Matrix4x3(Vector3D(n[0]*n[0]*(1-cos(rad)) + cos(rad),
									   n[0]*n[1]*(1-cos(rad)) + n[2]*sin(rad),
									   n[0]*n[2]*(1-cos(rad)) - n[1]*sin(rad)),
							  
							  Vector3D(n[0]*n[1]*(1-cos(rad)) - n[2]*sin(rad),
									   n[1]*n[1]*(1-cos(rad)) + cos(rad),
									   n[1]*n[2]*(1-cos(rad)) + n[0]*sin(rad)),
							  
							  Vector3D(n[0]*n[2]*(1-cos(rad)) + n[1]*sin(rad),
									   n[1]*n[2]*(1-cos(rad)) - n[0]*sin(rad),
									   n[2]*n[2]*(1-cos(rad)) + cos(rad)),
							  Vector3D(0,0,0));
	
	m_transform *= mat;
	setPosition(trans);
	
}
